package com.mall.test.domain.dto;

import lombok.Data;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Data
public class SalesManege {

    private Map<String,ProductInfo> Produces;

    public SalesManege(){
        this.Produces = new HashMap<>();
    }

    public void addProductInfo(String goodsName,Integer month,Integer sales){
       //判断是否存在次映射
        Produces.computeIfAbsent(goodsName,key->new ProductInfo(goodsName));
        Produces.get(goodsName).addSalesRecord(month,sales);
    }

    public ProductInfo getProductByGoodsName(String goodsName){
        ProductInfo productInfo = Produces.get(goodsName);
        return productInfo;
    }
    public List<ProductInfo> getAll(){
        return (List<ProductInfo>) Produces.values();
    }
}
